﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Student
{
    class Student : IComparable, ICloneable
    {
        private string firstName = null;
        private string middleName = null;
        private string lastName = null;
        private string ssn = null;
        private string address = null;
        private string mobilePhone = null;
        private string eMail = null;
        private string course = null;
        private Specialities specialty = Specialities.none;
        private Universities university = Universities.none;
        private Faculties faculty = Faculties.none;

        public string FirstName
        {
            get { return this.firstName; }
        }

        public string MiddleName
        {
            get { return this.middleName; }
        }

        public string LastName
        {
            get { return this.lastName; }
        }

        public string SSN
        {
            get { return this.ssn; }
        }

        public string Address
        {
            get { return this.address; }
            set { this.ssn = value; }
        }

        public string MobilePhone
        {
            get { return this.mobilePhone; }
            set { this.mobilePhone = value; }
        }

        public string EMail
        {
            get { return this.eMail; }
            set { this.eMail = value; }
        }

        public string Course
        {
            get { return this.course; }
            set { this.Course = value; }
        }

        public Specialities Speciality
        {
            get { return this.specialty; }
            set { this.specialty = value; }
        }

        public Universities University
        {
            get { return this.university; }
            set { this.university = value; }
        }

        public Faculties Faculty
        {
            get { return this.faculty; }
            set { this.faculty = value; }
        }

        public Student(string firstName, string middleName, string lastName, string ssn, string address, string mobilePhone,
             string eMail, string course, Specialities specialty, Universities university, Faculties faculty)
        {
            this.firstName = firstName;
            this.middleName = middleName;
            this.lastName = lastName;
            this.ssn = ssn;
            this.address = address;
            this.mobilePhone = mobilePhone;
            this.eMail = eMail;
            this.course = course;
            this.specialty = specialty;
            this.university = university;
            this.faculty = faculty;
        }

        public override bool Equals(object obj)
        {
            Student student = obj as Student;
            if (student == null)
            {
                return false;
            }
            if (this.firstName != student.firstName)
            {
                return false;
            }
            if (this.middleName != student.middleName)
            {
                return false;
            }
            if (this.lastName != student.lastName)
            {
                return false;
            }
            return true;
        }

        public override int GetHashCode()
        {
            return this.firstName.GetHashCode() ^ this.middleName.GetHashCode() ^ this.lastName.GetHashCode();
        }

        public override string ToString()
        {
            return String.Format("Full Name: {0}\nSSN: {1}\nAddress: {2}\nMobile Phone: {3}\ne-mail: {4}\n" +
                "Course: {5}\nSpecialty: {6}\nUniversity: {7}\nFaculty: {8}\n",
                this.firstName + " " + this.middleName + " " + this.lastName, this.ssn, this.address,
                this.mobilePhone, this.eMail, this.course, this.specialty, this.university, this.faculty);
        }

        public static bool operator == (Student student1, Student student2)
        {
            return student1.Equals(student2);
        }

        public static bool operator !=(Student student1, Student student2)
        {
            return !(student1.Equals(student2));
        }

        public int CompareTo(object obj)
        {
            Student otherStudent = obj as Student;
            if (otherStudent == null)
            {
                throw new ArgumentException();
            }

            string currentStudentFullName = this.firstName + " " + this.middleName + " " + this.lastName;
            string otherStudentFullName = otherStudent.firstName + " " + otherStudent.middleName + " " + otherStudent.lastName;

            if (currentStudentFullName.CompareTo(otherStudentFullName) == 0)
            {
                return this.SSN.CompareTo(otherStudent.SSN);
            }
            else return currentStudentFullName.CompareTo(otherStudentFullName);
        }

        public object Clone()
        {
            Student newStudent = new Student(this.firstName, this.middleName, this.lastName, this.ssn, this.address,
                this.mobilePhone, this.eMail, this.course, this.specialty, this.university, this.faculty);
            return newStudent;
        }
    }
}
